package com.example.friendfindertwo;

import com.example.friendfindertwo.R;
import com.example.friendfindertwo.adapter.FriendPagerAdapter;

import android.app.ActionBar;
import android.app.ActionBar.Tab;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.ViewPager;

public class FriendManagerActivity extends FragmentActivity implements ActionBar.TabListener{
	private ViewPager viewPager;
	private ActionBar actionBar;
	
	@Override
	protected void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_friend_pager);
		viewPager = (ViewPager) findViewById(R.id.pager);
		viewPager.setAdapter(new FriendPagerAdapter(getSupportFragmentManager()));

		actionBar = getActionBar();
		
		viewPager.setOnPageChangeListener(new ViewPager.SimpleOnPageChangeListener(){
			@Override
			public void onPageSelected(int position) {
				// TODO Auto-generated method stub
				super.onPageSelected(position);
				actionBar.setSelectedNavigationItem(position);
			}
		});
		
        // get action bar   
        
        actionBar.setSubtitle(R.string.title_friend_manager);
        // Enabling Up / Back navigation
        actionBar.setDisplayHomeAsUpEnabled(true);

		// get action bar   
		ActionBar actionBar = getActionBar();
		actionBar.setSubtitle(R.string.title_friend_manager);
		// Enabling Up / Back navigation
		actionBar.setDisplayHomeAsUpEnabled(true);
        
        actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
        
        for(int i=0; i<viewPager.getAdapter().getCount() ; i++){
        	actionBar.addTab(actionBar.newTab()
        			.setText(viewPager.getAdapter().getPageTitle(i))
        			.setTabListener(this));
        }
        
	}

	@Override
	public void onTabReselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void onTabSelected(Tab tab, FragmentTransaction ft) {
		viewPager.setCurrentItem(tab.getPosition());
		
	}

	@Override
	public void onTabUnselected(Tab tab, FragmentTransaction ft) {
		// TODO Auto-generated method stub
		
	}

}
